package com.gzhu.knowledgeAdmin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gzhu.knowledgeAdmin.common.result.R;
import com.gzhu.knowledgeAdmin.entity.TDxqmT;
import com.gzhu.knowledgeAdmin.service.impl.TDxqmTServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/signatures")
public class SignatureController {

    @Autowired
    private TDxqmTServiceImpl tDxqmTServiceImpl;

    @GetMapping("/search")
    public R searchSignatures(
            @RequestParam(required = false) String fqmnr,
            @RequestParam(required = false) String fshzt
    ) {
        QueryWrapper<TDxqmT> wrapper = new QueryWrapper<>();
        if (fqmnr != null) {
            wrapper.like("F_QMNR", fqmnr);
        }
        if (fshzt != null) {
            wrapper.eq("F_SHZT", fshzt);
        }
        return R.ok(tDxqmTServiceImpl.list(wrapper));
    }

    @PostMapping("/create")
    public R createSignature(@RequestBody TDxqmT tDxqmT) {
        Integer success = tDxqmTServiceImpl.addQM(tDxqmT);
        if (success != 0) {
            return R.ok(new ResponseEntity<>(tDxqmT, HttpStatus.CREATED));
        }else {
            return R.error();
        }
    }

}
